﻿using IDAL;
using Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DAL
{
    public class D_Address : IAddress
    {
        public void Add(Address item)
        {
            CakeEntities db = new CakeEntities();
            db.Address.Add(item);
            db.SaveChanges();
        }

        public void Delete(int id)
        {
            CakeEntities db = new CakeEntities();
            db.Address.Remove(db.Address.Find(id));
            db.SaveChanges();
        }

        public Address FindById(int id)
        {
            return new CakeEntities().Address.Find(id);
        }

        public List<Address> GetAll()
        {
            return new CakeEntities().Address.ToList();
        }

        public void Updata(int id, Address item)
        {
            CakeEntities db = new CakeEntities();
            var data= db.Address.Find(id);
            if (data!=null)
            {
                data.ToName = item.ToName;
                data.Phone=item.Phone;
                data.Areas=item.Areas;
                data.AddressInfo=item.AddressInfo;
                data.IsDefault=item.IsDefault;
                data.Customer=item.Customer;
                data.SendName=item.SendName;
                data.SendPhone=item.SendPhone;
                db.SaveChanges();
            }
        }
    }
}
